﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WorkRecorder.Data;
using WorkRecorder.Business;
using System.IO;
using System.Threading;

namespace WorkerRecorderTestProject
{
    [TestClass]
    public class DataMapperXmlImplTest
    {
 
        [TestMethod]
        public void SerializeTest()
        {
            string testPath = "Records.xml";
            Records<Record> recordSet = new Records<Record>();
            Record r1 = new Record();
            r1.RType = "Work";
            r1.Comments = "Some test comments";
            r1.StartTime = DateTime.Now;
            Thread.Sleep(2500);
            r1.EndTime = DateTime.Now;
            r1.TimeElapsed = r1.EndTime.Subtract(r1.StartTime).Ticks;
             

            Record r2 = new Record();
            r2 = r1;
            r2.RType = "School";

            recordSet.RecordSet.Add(r1);
            recordSet.RecordSet.Add(r2);


            DataMapperXmlImpl dm = new DataMapperXmlImpl();
            dm.SaveGraph(recordSet, testPath);

            Assert.IsTrue(File.Exists(testPath));
        }


        [TestMethod]
        public void DeserializeTest()
        {

            string testPath = "Records.xml";
            DataMapperXmlImpl dm = new DataMapperXmlImpl();
            Records<Record> recordSet = dm.ReadGraph(testPath);
            TimeSpan ts = TimeSpan.FromTicks(recordSet.RecordSet.ElementAt(0).TimeElapsed);
            Assert.IsNotNull(recordSet);
        }
    }
}
